﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using WF.Common;

namespace SHZYWF.Web
{
    public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            #region 获取网站路径
            string AppPath = Context.Request.ApplicationPath; // pattern AppPath = "/CCOO"
            string RemoteHost = Context.Request.ServerVariables.Get("SERVER_NAME");
            string ServerPort = Context.Request.ServerVariables["SERVER_PORT"].ToString();
            AppPath = AppPath.Trim();
            //如果应用程序为一个站点，调整 AppPath 的值为 "http://hostname:80/" 字符串,否则为 "http://hostname:80/ccoo/"

            if (AppPath.Trim() != "/")
            {
                AppPath = AppPath + "/";
            }
            AppPath = "http://" + RemoteHost + ":" + ServerPort + AppPath;
            Application.Add(ApplicationKeys.AppPath, AppPath);
            #endregion
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown
            #region 获取网站路径
            string AppPath = Context.Request.ApplicationPath; // pattern AppPath = "/CCOO"
            string RemoteHost = Context.Request.ServerVariables.Get("SERVER_NAME");
            string ServerPort = Context.Request.ServerVariables["SERVER_PORT"].ToString();
            AppPath = AppPath.Trim();
            //如果应用程序为一个站点，调整 AppPath 的值为 "http://hostname:80/" 字符串,否则为 "http://hostname:80/ccoo/"

            if (AppPath.Trim() != "/")
            {
                AppPath = AppPath + "/";
            }
            AppPath = "http://" + RemoteHost + ":" + ServerPort + AppPath;

            Session.Add("AppPath", AppPath);
            #endregion
        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }

    }
}
